package com.papers.juan.utils;

import lombok.NoArgsConstructor;

import java.util.List;

@NoArgsConstructor
public class Node implements Comparable<Node> {

    private String id;
    private String nodeName;
    private String nodeCode;
    private String parentId;
    private Long sort;

    private String treeType = "knowledge";

    public String getNodeCode() {
        return nodeCode;
    }

    public void setNodeCode(String nodeCode) {
        this.nodeCode = nodeCode;
    }

    public String getTreeType() {
        return treeType;
    }

    public void setTreeType(String treeType) {
        this.treeType = treeType;
    }

    public Long getSort() {
        return sort;
    }
    public void setSort(Long sort) {
        this.sort = sort;
    }
    public String getid() {
        return id;
    }
    public void setid(String id) {
        this.id = id;
    }
    public String getNodeName() {
        return nodeName;
    }
    public void setNodeName(String nodeName) {
        this.nodeName = nodeName;
    }
    public String getParentId() {
        return parentId;
    }
    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    public Node(String id, String nodeName, String parentId, Long sort) {
        this.id = id;
        this.nodeName = nodeName;
        this.parentId = parentId;
        this.sort = sort;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) { return true; }
        if (obj == null) { return false; }
        if (getClass() != obj.getClass()) { return false; }
        Node other = (Node) obj;
        if (id == null) {
            if (other.id != null) { return false; }
        } else if (!id.equals(other.id)) {
            return false;
        }
        if (nodeName == null) {
            if (other.nodeName != null) { return false; }
        } else if (!nodeName.equals(other.nodeName)) {
            return false;
        }
        if (parentId == null) {
            if (other.parentId != null) { return false; }
        } else if (!parentId.equals(other.parentId)) {
            return false;
        }
        if (sort == null) {
            if (other.sort != null) { return false; }
        } else if (!sort.equals(other.sort)) {
            return false;
        }
        return true;
    }

    /**
     * 下级节点集合
     */
    private List<Node> children;

    public List<Node> getchildren() {
        return children;
    }
    public void setchildren(List<Node> children) {
        this.children = children;
    }
    @Override
    public int compareTo(Node node) {
        //正序
        return this.sort.compareTo(node.sort);
        //倒序
//			return node.sort.compareTo(this.sort);
    }
}
